package com.zhuoshi.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.Wd_contractModel;
import com.zhuoshi.bean.Wd_ht_customerModel;
import com.zhuoshi.bean.Wd_ht_roomModel;
import com.zhuoshi.service.Wd_contractModelService;
import com.zhuoshi.service.Wd_ht_customerModelService;
import com.zhuoshi.service.Wd_ht_roomModelService;

@Controller
@RequestMapping("/contract")
public class Wd_contractAction {
	@Autowired
	private Wd_contractModelService contractService;
	
	@Autowired
	Wd_ht_roomModelService wd_ht_roomModelService ;
	
	@Autowired
	private Wd_ht_customerModelService customerModelService;
	//查询
	@RequestMapping("contract_select.do")
	public String selectContract(Wd_contractModel bean,Model model){
		if (bean.getContractContent() != null && "".equals(bean.getContractContent().trim())) {
			bean.setContractContent(null);
		}
		if (bean.getFirstParty() != null && "".equals(bean.getFirstParty().trim())) {
			bean.setFirstParty(null);
		}
		if (bean.getSecondParty() != null && "".equals(bean.getSecondParty().trim())) {
			bean.setSecondParty(null);
		}
		List<Wd_contractModel> list = contractService.selectAllContract(bean);
		model.addAttribute("clist", list);
		return "Wd_Contract_select";
	}
	
	//删除
	@RequestMapping("delete_contract.do")
	public String deleteContract(String contractId){
		contractService.deleteByPrimaryKey(contractId);
		return "redirect:contract_select.do";
	}
	
	@RequestMapping("/toAdd.do")
	public String toadd(){
		return "" ;
	}
	
	@RequestMapping("/toupdate_contract.do")
	public String toupdate_contract(String contractId,Model model){
		Wd_contractModel bean = contractService.selectByPrimaryKey(contractId);
		List<Wd_ht_roomModel> roomList = wd_ht_roomModelService.selectAll(null);
		List<Wd_ht_customerModel> customerList = customerModelService.selectAllCustomer();
		model.addAttribute("bean",bean) ;
		model.addAttribute("roomList", roomList);
		model.addAttribute("customerList", customerList);
		return "Wd_contract_update";
	}
	
	@RequestMapping("/update_contract.do")
	public String update_contract(Wd_contractModel record){
		contractService.updateByPrimaryKeySelective(record);
		return "redirect:contract_select.do" ;
	}
}
